package com.innovation.chengzhangriji.ui.widget;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.innovation.chengzhangriji.R;

public class HeadPictureViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

    public static interface OpenPictureListener {

        void openPicture(int position);

    }

    private OpenPictureListener mOpenPictureListener;

    private ImageView mIvContent;

    private Context mContext;

    public HeadPictureViewHolder(Context context, View itemView) {
        super(itemView);
        mContext = context;
        mIvContent = (ImageView) itemView.findViewById(R.id.picture_content);
        mIvContent.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.picture_content:
                openPicture();
                break;
        }
    }

    public void setOpenPictureListener(OpenPictureListener openPictureListener) {
        mOpenPictureListener = openPictureListener;
    }

    public ImageView getPicture() {
        return mIvContent;
    }

    private void openPicture() {
        if (mOpenPictureListener != null) {
            mOpenPictureListener.openPicture(getPosition());
        }
    }

}
